package logic

import (
	"api/pkg"
	"context"
	"house_srv/house"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseReleaseLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewHouseReleaseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseReleaseLogic {
	return &HouseReleaseLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *HouseReleaseLogic) HouseRelease(req *types.HouseReleaseRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	release, err := l.svcCtx.HouseSrv.HouseRelease(l.ctx, &house.HouseReleaseRequest{
		UserId:    req.UserId,
		HouseName: req.HouseName,
		Price:     req.Price,
		Floor:     req.Floor,
		Area:      req.Area,
		Cover:     req.Cover,
		Address:   req.Address,
		Describe:  req.Describe,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: pkg.Tri(err.Error()),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "房源发布成功",
		Data: map[string]interface{}{
			"Release": release,
		},
	}, nil
}
